#include "SerialDebugger.h"
#include <stdio.h>

#define DBG_ATTRIBUTE_NULL           0x00000000
#define DBG_ATTRIBUTE_COLOR_MASK     0x0000000f
#define DBG_ATTRIBUTE_BLOD_MASK      0x00000010
#define DBG_ATTRIBUTE_FAKE_MASK      0x00000020
#define DBG_ATTRIBUTE_UNDERLINE_MASK 0x00000040
#define DBG_ATTRIBUTE_FLASH_MASK     0x00000080
#define DBG_ATTRIBUTE_INVERSE_MASK   0x00000100
#define DBG_ATTRIBUTE_HIDE_MASK      0x00000200

struct SerialDebuggerDevice
{
    char SerialDebuggerTextBuffer[DBG_CFG_TEXT_MAX_LENGTH];
    int (*ConsoleOutput)(debug_content_t content, debug_attr_t attributes);
};

int ConsolePrint(debug_content_t content, debug_attr_t attributes)
{
    if(attributes != DBG_ATTRIBUTE_NULL)
    {
        switch(attributes & DBG_ATTRIBUTE_COLOR_MASK)
        {
            case DBG_COLOR_RED:printf("\033[31m");break;
            case DBG_COLOR_GREEN:printf("\033[32m");break;
            case DBG_COLOR_YELLOW:printf("\033[33m");break;
            case DBG_COLOR_BLUE:printf("\033[34m");break;
            case DBG_COLOR_MAGENTA:printf("\033[35m");break;
            case DBG_COLOR_CYAN:printf("\033[36m");break;
            case DBG_COLOR_BLACK:
            default:;break;
        }
        if(attributes & DBG_ATTRIBUTE_BLOD_MASK)
        {
            printf("\033[1m");
        }
        if(attributes & DBG_ATTRIBUTE_FAKE_MASK)
        {
            printf("\033[2m");
        }
        if(attributes & DBG_ATTRIBUTE_UNDERLINE_MASK)
        {
            printf("\033[4m");
        }
        if(attributes & DBG_ATTRIBUTE_FLASH_MASK)
        {
            printf("\033[5m");
        }
        if(attributes & DBG_ATTRIBUTE_INVERSE_MASK)
        {
            printf("\033[7m");
        }
        if(attributes & DBG_ATTRIBUTE_HIDE_MASK)
        {
            printf("\033[8m");
        }
    }
    puts(content);
    printf("\033[0m");
    return 0;
} 

